#include "imageproperty.h"
#include "ui_imageproperty.h"

ImageProperty::ImageProperty(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ImageProperty)
{
    ui->setupUi(this);
    my_api = NULL;
    image_data.clear();
    ClearFolderList();
}

ImageProperty::~ImageProperty()
{
    delete ui;
}

void ImageProperty::on_pushButton_2_clicked()
{
    hide();
}

void ImageProperty::SetAPIHandle(ShotScreensWebAPI *api)
{
    my_api = api;
}

void ImageProperty::ClearFolderList()
{
    ui -> comboBox -> clear();
    folders.clear();
    folderNames.clear();
    folderHashes.clear();
}

void ImageProperty::SetImageData(QByteArray data)
{
    image_data = data;
}

void ImageProperty::FillFolders()
{
    ClearFolderList();
    int size = my_api->folderNames.count();

    for(int i = 0; i<size; i++)
    {
        FOLDER_ITEM folder;

        folder.folder_name = my_api -> folderNames.at(i);
        folder.folder_hash = my_api -> folderHashes.at(i);
        folders.append(folder);
        ui -> comboBox -> addItem(folder.folder_name);
    }
}



void ImageProperty::on_pushButton_3_clicked()
{
    QString image_title = ui->lineEdit->text();
    my_api -> UploadImage(image_title, folders.at(ui->comboBox->currentIndex()).folder_hash.toAscii().data(), image_data);
    ui->lineEdit->setText("");

    hide();
}

